import axios from 'axios'

// 进行一些全局配置
// 公共路由(网络请求地址)
axios.defaults.baseURL = 'http://localhost:3000';
// 配置默认请求头
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
// axios.defaults.headers['Content-Type'] = 'multipart/form-data'
// application/json;charset=utf-8
// herders: {
//     "Content-Type": 'multipart/form-data'
// }

// 请求响应超时时间
axios.defaults.timeout = 5000

export default {
    get: function (path = '' ,data = {}){
        return new Promise (function (resolve,reject){
            axios.get(path, {
                params: data
            })
            .then(function(response) {
                resolve(response)
            })
            .catch(function(error) {
                reject(error)
            });
        });
    },
    post: function(path = '', data = {}) {
        return new Promise(function(resolve, reject) {
            axios.post(path, data)
                .then(function(response) {
                    resolve(response.data);
                })
                .catch(function(error) {
                    reject(error);
                });
        });
    },
}